//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _SQL_CONF_H_
#define _SQL_CONF_H_

namespace sql_conf {

static const char sPragmas[]=
        "PRAGMA synchronous=0;"
        "PRAGMA count_changed=0;"
        "PRAGMA cache_size=5000;"
        "PRAGMA auto_vacuum=0;"
        "PRAGMA temp_store=MEMORY;"
        "PRAGMA legacy_file_format=OFF;"
        "PRAGMA foreign_keys=ON;"
        "PRAGMA encoding=\"UTF-8\";";

static const char sCreateTables[]=
        "CREATE TABLE Folders"
        "("
        "   FolderID          INTEGER PRIMARY KEY NOT NULL,"
        "   Path              TEXT NOT NULL,"
        "   ParentID          INTEGER,"
        "   "
        "   UNIQUE (Path)"
        ");"
        ""
        "CREATE TABLE Keys"
        "("
        "   KeyID             INTEGER PRIMARY KEY NOT NULL,"
        "   Folder            INTEGER NOT NULL,"
        "   Name              TEXT NOT NULL,"
        "   DataType          INTEGER NOT NULL,"
        "   DataValue         BLOB NOT NULL,"
        "   "
        "   FOREIGN KEY(Folder) REFERENCES Folders(FolderID)"
        "   UNIQUE(Folder,Name)"
        ");";

static const char sDefaultData[]=
        "BEGIN TRANSACTION;"
        ""
        "INSERT INTO Folders(Path) VALUES('/');"
        ""
        "END TRANSACTION;";

static const char sInsertFolder[]=
        "INSERT INTO Folders(Path,ParentID) VALUES(?,?);";

static const int sInsertFolder_Path=1;
static const int sInsertFolder_Parent=2;

static const char sInsertKey[]=
        "INSERT OR REPLACE INTO Keys(Folder,Name,DataType,DataValue) VALUES(?,?,?,?);";

static const int sInsertKey_Folder=1;
static const int sInsertKey_Name=2;
static const int sInsertKey_DataType=3;
static const int sInsertKey_DataValue=4;

static const char sGetFolderID[]=
        "SELECT FolderID FROM Folders WHERE Path=?";

static const int sGetFolderID_Path=1;

static const char sGetChildren[]=
        "SELECT FolderID,Path FROM Folders WHERE ParentID=?";

static const int sGetChildren_ParentID=1;

static const char sGetKey[]=
        "SELECT KeyID,DataType,DataValue FROM Keys WHERE Folder=? AND Name=?";

static const int sGetKey_Folder=1;
static const int sGetKey_Name=2;

static const char sGetKeyNames[]=
        "SELECT Name FROM Keys WHERE Folder=?";

static const char sGetKeys[]=
        "SELECT Name,DataType,DataValue FROM Keys WHERE Folder=?";

/*namespace sql_conf*/ }

#endif
